<template>
  <div class="app-container">
    <!--<tree-table v-loading="loading" :data="authData" element-loading-text="拼命加载中">
      <el-table-column label="名称" width="160" align="center">
        <template slot-scope="scope">
          {{ scope.row.text }}
        </template>
      </el-table-column>
      <el-table-column label="url" width="160" align="center">
        <template slot-scope="scope">
          {{ scope.row.object.url }}
        </template>
      </el-table-column>
      <el-table-column label="icon" width="160" align="center">
        <template slot-scope="scope">
          {{ scope.row.object.icon }}
        </template>
      </el-table-column>
      <el-table-column label="类型" prop="object.type">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.object.type === null" />
          <el-tag v-if="scope.row.object.type === 0">目录</el-tag>
          <el-tag v-if="scope.row.object.type === 1">菜单</el-tag>
          <el-tag v-if="scope.row.object.type === 2">操作</el-tag>
        </template>
      </el-table-column>
    </tree-table>-->
    <tree-table
      v-loading="loading"
      :data="authData"
      :columns="columns"
      :expand-all="true"
      border
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="图标" width="60" align="center">
        <template slot-scope="scope">
          <span :class="'fa fa-'+scope.row.object.icon" />
        </template>
      </el-table-column>
      <el-table-column label="类型" prop="object.type" width="100" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.object.type === null" />
          <el-tag v-if="scope.row.object.type === 0" type="info">目录</el-tag>
          <el-tag v-if="scope.row.object.type === 1">链接</el-tag>
          <el-tag v-if="scope.row.object.type === 2" type="warning">按钮</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="权限值" prop="object.value" />
      <el-table-column label="路径" prop="object.url" />
      <el-table-column label="排序" prop="object.sort" />
      <el-table-column label="状态" prop="object.status" width="100" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.object.type === null" />
          <el-tag v-if="scope.row.object.status === 1" type="success">正常</el-tag>
          <el-tag v-if="scope.row.object.status === 0" type="danger">禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="250">
        <template slot-scope="scope">
          <el-button size="mini" @click="showAddDialog(scope.row.id,scope.row.object.type)">增加</el-button>
          <el-button size="mini" @click="showEditDialog(scope.$index,scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="remove(scope.$index,scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </tree-table>
  </div>
</template>

<script>
import TreeTable from '@/components/TreeTable/index'
import { list } from '@/api/auth'

export default {
  components: { TreeTable },
  data() {
    return {
      loading: false,
      columns: [
        {
          text: '名称',
          value: 'text',
          width: 200
        }/*,
        {
          text: '图标',
          value: 'icon',
          width: 100
        }*/
      ],
      authData: []
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.loading = true
      list().then(response => {
        this.authData = response.data
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
